/** 
 * @file XmlParser.h
 * @Synopsis  xml's parser use by miniXML
 * @author JzeTech 
 * @version 0.1 beta
 * @date 2009-08-27
 */

 #ifndef _XMLPARSER_H_
 #define _XMLPARSER_H_

#include "Iconv.h"
#include "mxml.h"

#ifndef bool
#define bool int
#define false 0
#define true 1
#endif

#define XMLHEADER "<?xml version=\"1.0\" encoding=\"gb2312\" ?>\n"
#define START_MESSAGE "<Message>\n"
#define END_MESSAGE "</Message>\n"

/* --------------------------------------------------------------------------*/
/** 
 * @Synopsis  create a xml file
 * 
 * @Param File *fp
 * 
 * @Returns  mxml_node_t* 
 */
/* ----------------------------------------------------------------------------*/
mxml_node_t* CreateXMLFile(FILE *fp);


/* --------------------------------------------------------------------------*/
/** 
 * @Synopsis  
 */
/* ----------------------------------------------------------------------------*/
mxml_node_t* ParseXMLFile(FILE* fp);


/* --------------------------------------------------------------------------*/
/** 
 * @Synopsis  
 * 
 * @Param node
 * @Param root
 */
/* ----------------------------------------------------------------------------*/
void mxmlGetNodeValue(mxml_node_t *node, mxml_node_t *root);


/* --------------------------------------------------------------------------*/
/** 
 * @Synopsis  
 * 
 * @Param node
 * 
 * @Returns   
 */
/* ----------------------------------------------------------------------------*/
int mxmlGetNodeAttrsValue(mxml_node_t *node);


/* --------------------------------------------------------------------------*/
/** 
 * @Synopsis  
 * 
 * @Param node
 * @Param root
 */
/* ----------------------------------------------------------------------------*/
bool RecursionNodes(mxml_node_t *node, mxml_node_t *root);


/* --------------------------------------------------------------------------*/
/** 
 * @Synopsis  
 * 
 * @Param p
 * 
 * @Returns   
 */
/* ----------------------------------------------------------------------------*/
mxml_node_t* ParserDataXML(void* p, int len);


/* --------------------------------------------------------------------------*/
/** 
 * @Synopsis  
 * 
 * @Returns   
 */
/* ----------------------------------------------------------------------------*/
void* RecvDataXMLFromFile();


/* --------------------------------------------------------------------------*/
/** 
 * @Synopsis  
 * 
 * @Param node
 * 
 * @Returns   
 */
/* ----------------------------------------------------------------------------*/
mxml_type_t mxmlTypeCallback(mxml_node_t *node);


/* --------------------------------------------------------------------------*/
/** 
 * @Synopsis  
 * 
 * @Param dstBuff
 * @Param srcBuff
 * @Param blen
 * @Param fStr
 * 
 * @Returns   
 */
/* ----------------------------------------------------------------------------*/
void* FilterCharacters(void* dstBuff, void* srcBuff, int blen, char* fStr);

/** 
 * @brief 
 * 
 * @param node
 * @param str
 * @param whitespace
 * 
 * @return 
 */
bool SetNodeTextValue(mxml_node_t* node, char* str, int whitespace);

/** 
 * @brief 
 * 
 * @param node
 * @param str
 * @param whitespace
 * 
 * @return 
 */
bool SetNodeElementValue(mxml_node_t* node, char* str);

/** 
 * @brief 
 * 
 * @param treeRoot
 * @param name
 * 
 * @return 
 */
mxml_node_t* HaveNode(mxml_node_t* treeRoot, const char* name);

/** 
 * @brief 
 * 
 * @param sourcebuf
 * @param sourcelen
 * @param destbuf
 * @param destlen
 * 
 * @return 
 */
int IsNeedIconv(char *sourcebuf,size_t sourcelen,char *destbuf,size_t destlen);

/** 
 * @brief 
 * 
 * @param node
 * @param name
 * 
 * @return 
 */
char* GetKeyValue(mxml_node_t* node, char *name);

/** 
 * @brief 
 * 
 * @param node
 * @param name
 * @param num
 * 
 * @return 
 */
void* GetNodeAttrsValue(mxml_node_t *node, const char* name, int num);

/** 
 * @brief 
 * 
 * @param node
 * 
 * @return 
 */
int GetNodeAttrsNum(mxml_node_t* node);

void SetNodeAttrValue(mxml_node_t* node, const char* name, const char* value);

mxml_node_t* SearchSubNode(mxml_node_t* subNode, mxml_node_t* root, const char* name);
#endif

